package db

import (
	"apifast/configs"
	"apifast/pkg/dao"
)

type Options struct {
	Name    string `json:"name"`
	Address string `json:"address"`
}

var _models []interface{}

func RegisterModel(dst ...interface{}) {
	_models = append(_models, dst...)
}

func Run() error {
	var o Options
	if err := configs.GViper.UnmarshalKey("sql", &o); err != nil {
		return err
	}
	db, err := dao.NewGormV2(o.Name, o.Address)
	if err != nil {
		return err
	}
	db.AutoMigrate(_models...)
	return nil
}
